"""
基础数据模型
"""
from datetime import datetime
from typing import Optional, List, Generic, TypeVar, Any, Dict

from pydantic import BaseModel, Field
from pydantic import BaseModel as GenericModel

T = TypeVar('T')


class BaseResponse(BaseModel):
    """基础响应模型"""
    success: bool = True
    message: Optional[str] = None


class ErrorResponse(BaseResponse):
    """错误响应模型"""
    success: bool = False
    detail: str
    code: int


class SuccessResponse(BaseResponse):
    """成功响应模型"""
    data: Optional[Dict[str, Any]] = None


class PaginatedResponse(GenericModel, Generic[T]):
    """分页响应模型"""
    items: List[T]
    total: int
    page: int
    size: int
    pages: int
    has_next: bool
    has_prev: bool


class TimestampMixin(BaseModel):
    """时间戳混合模型"""
    created_at: datetime = Field(default_factory=datetime.now)
    updated_at: Optional[datetime] = None


class IDMixin(BaseModel):
    """ID混合模型"""
    id: int
